// 实时数据轮询时间分配工具类
import 'package:bluetooth_protocols_parser_plugin/library.dart';
import 'package:inmotion_pro/service/realtime_data_server/realtime_data_service.dart';
import 'package:inmotion_pro/service/vehicle_connection_service.dart';

class RealtimeDataPollingTimeHelper {
  // 车辆首页实时数据轮询时间类型列表
  static List<(PollingTimerType, int)> get vehicleHomePagePollingTypes {
    final connectedMethod = VechileConnectionService.to.connectedMethod;
    switch (connectedMethod) {
      case MessageSendMethod.bluetooth:
        return [
          (PollingTimerType.integratedRealtimeAll, 2000),
          (PollingTimerType.realtimeAll, 2000),
          (PollingTimerType.realtimeStatisticsTotal, 8000),
        ];
      case MessageSendMethod.http:
        return [
          (PollingTimerType.integratedRealtimeAll, 5000),
          (PollingTimerType.realtimeAll, 5000),
          (PollingTimerType.realtimeStatisticsTotal, 12000),
        ];
      case MessageSendMethod.bluetoothAndHttp:
        // 时间间隔为：蓝牙 + HTTP / 2
        return [
          (PollingTimerType.integratedRealtimeAll, 3500),
          (PollingTimerType.realtimeAll, 3500),
          (PollingTimerType.realtimeStatisticsTotal, 10000),
        ];
    }
  }

  // 车辆详情页实时数据轮询时间类型列表
  static List<(PollingTimerType, int)> get vehicleDetailPagePollingTypes {
    final connectedMethod = VechileConnectionService.to.connectedMethod;
    switch (connectedMethod) {
      case MessageSendMethod.bluetooth:
        return [
          (PollingTimerType.integratedRealtimeAll, 700),
          (PollingTimerType.realtimeAll, 900),
          (PollingTimerType.realtimeStatisticsOnce, 2000),
          (PollingTimerType.realtimeStatisticsTotal, 5000),
        ];
      case MessageSendMethod.http:
        return [
          (PollingTimerType.integratedRealtimeAll, 3000),
          (PollingTimerType.realtimeAll, 3000),
          (PollingTimerType.realtimeStatisticsOnce, 5000),
          (PollingTimerType.realtimeStatisticsTotal, 10000),
        ];
      case MessageSendMethod.bluetoothAndHttp:
        // 时间间隔为：蓝牙 + HTTP / 2
        return [
          (PollingTimerType.integratedRealtimeAll, 1850),
          (PollingTimerType.realtimeAll, 1950),
          (PollingTimerType.realtimeStatisticsOnce, 3500),
          (PollingTimerType.realtimeStatisticsTotal, 7500),
        ];
    }
  }

  // 车辆设置页实时数据轮询时间类型列表
  static List<(PollingTimerType, int)> get vehicleSettingPagePollingTypes {
    return [
      (PollingTimerType.realtimeSetting, 100000),
    ];
  }

  // 车辆电池信息页实时数据轮询时间类型列表
  static List<(PollingTimerType, int)> get vehicleBatteryInfoPagePollingTypes {
    final connectedMethod = VechileConnectionService.to.connectedMethod;
    switch (connectedMethod) {
      case MessageSendMethod.bluetooth:
        return [
          (PollingTimerType.realtimeBattery, 3000),
        ];
      case MessageSendMethod.http:
        return [
          (PollingTimerType.realtimeBattery, 5000),
        ];
      case MessageSendMethod.bluetoothAndHttp:
        // 时间间隔为：蓝牙 + HTTP / 2
        return [
          (PollingTimerType.realtimeBattery, 4000),
        ];
    }
  }
}
